layui.define([ 'form', 'laydate', 'table'], function(exports) {
    var form = layui.form;
    var table = layui.table;
    var index = layui.index;
    var view = {
        init:function(){
        	  this.initSubmit();
        	  this.show();
        },
        show:function(){
        	
        	showLeftAside();
        	showTax();
        },
        initSubmit:function(){
            //删除发票
            $(document).on('click','.delete',function(){
                var t=$(this).attr('omit_id');
                doAjax('/user/userTax/delTax.json','post',{'taxId':t},function(res){
                    if(res.code == '200')
                    {
                        location.href = location.href;
                        $.alert('success','删除成功');
                    }
                    else
                    {
                        $.alert('error','删除失败');
                    }

                })
            })
            
             //新增/编辑增值发票
            $(document).on('click','.zjshdz,.editor',function(){
            	var t=$(this).attr('id_alter');
            	if(!t){t=0;}
                doAjax('/html/addOrEditTax.html', 'get', {'taxId':t}, function (res) {
                	if(t>0){
                		 doAjax('/user/userTax/getTax.json', 'post', {'taxId':t}, function (data) {
                			 var userTax=data.data;
                			 $('.op_splice_taxCompany').val(userTax.taxCompany);
                			 $('.op_splice_taxIdentification').val(userTax.taxIdentification);
                			 $('.op_splice_taxAddr').val(userTax.taxAddr);
                			 $('.op_splice_taxTel').val(userTax.taxTel);
                			 $('.op_splice_taxAccountName').val(userTax.taxAccountName);
                			 $('.op_splice_taxNumber').val(userTax.taxNumber);
                			 $('#taxId').val(t);
                			 
                		 })
                	}
                    $.prompt({
                        style: '',
                        title: '增值税专用发票',
                        con: res,
                    });
                }, '', 'html')
            })
            
             //确认增值税发票
            $(document).on('click','.taxAdd_sub',function(){
                if (!validForm_01.check(false)) {
                    $('.invoice_bill li p').show();
                    return;
                }
                var tax_company=$('.op_splice_taxCompany').val(),//公司名称：
                    tax_identification=$('.op_splice_taxIdentification').val(),//纳税人识别号：
                    tax_company_addr=$('.op_splice_taxAddr').val(),//公司地址
                    tax_tel=$('.op_splice_taxTel').val(),//
                    tax_account_name=$('.op_splice_taxAccountName').val(),//
                    tax_number=$('.op_splice_taxNumber').val(),//
//                    tax_content=$('.invoice_bill select').eq(0).val(),//
                    tax_id=$('#taxId').val()?$('#taxId').val():"0";
                var taxData={
                    taxAccountName:tax_account_name,
                    taxAddr:tax_company_addr,
                    taxCompany:tax_company,
                    taxId:tax_id,
                    taxIdentification:tax_identification,
                    taxNumber:tax_number,
                    taxTel:tax_tel
                }
                doAjax('/user/userTax/saveTax.json','post',{"taxData":JSON.stringify(taxData)},function(res){
                	 location.href = location.href;
                });
                $('.popup-btn-close').click();


            })

            $(document).on('click','.bill-but-false',function(){
                $('.popup-btn-close').click();
            })
             $(document).on('click','.qx_sub ',function(){
            	 $('.popup-btn-close').click();
            })
          
        }
            
    }
    exports('index',view);
	
});